package com.dd.logistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.logistics.entity.Supplier;
import com.dd.logistics.mapper.SupplierMapper;
import com.dd.logistics.service.SupplierService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
    
    @Override
    public Supplier getByName(String name) {
        QueryWrapper<Supplier> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name);
        return this.getOne(wrapper);
    }
    
    @Override
    @Transactional
    public boolean updateSupplierInfo(Supplier supplier) {
        if (supplier.getId() != null) {
            return this.updateById(supplier);
        }
        return false;
    }
    
    @Override
    public boolean checkSupplierExists(Long supplierId) {
        if (supplierId == null) {
            return false;
        }
        return this.getById(supplierId) != null;
    }
} 